package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import liumengbaio.lolzhangyoubao.Activity.View.MsgDialog;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/12.
 */
public class msgActivity extends AppCompatActivity {
    private boolean flag = true, toggle_one = true, toggle_two = true, toggle_three = true;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.msg_activity);
        sp = getSharedPreferences("msgSetting", MODE_PRIVATE);
        editor = sp.edit();
        findViewById(R.id.edit_head_left_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.btn_switch).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag) {
                    findViewById(R.id.btn_switch).setBackgroundResource(R.mipmap.user_switch_on);
                    flag = false;
                } else {
                    findViewById(R.id.btn_switch).setBackgroundResource(R.mipmap.user_switch_off);
                    flag = true;
                }
            }
        });
        findViewById(R.id.relative_nomsg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        findViewById(R.id.relative_nomsg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setDoBlack_voice();
            }
        });
    }

    private void setDoBlack_voice() {
        final MsgDialog.Builder msg_dialog = new MsgDialog.Builder(this);
        msg_dialog.setTitle("消息免打扰设置");
        msg_dialog.setToggle_one(sp.getBoolean("toggle_one",false));
        msg_dialog.setToggle_one(sp.getBoolean("toggle_two",false));
        msg_dialog.setToggle_one(sp.getBoolean("toggle_three",false));
        msg_dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Toast.makeText(msgActivity.this, "设置成功", Toast.LENGTH_SHORT).show();
            }
        });
        msg_dialog.setDialogOnclick_One(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (toggle_one) {
                    v.setBackgroundResource(R.mipmap.user_switch_on);
                    toggle_one = false;
                } else {
                    v.setBackgroundResource(R.mipmap.user_switch_off);
                    toggle_one = true;
                }
                editor.putBoolean("toggle_one", toggle_one);
                editor.commit();
            }
        });
        msg_dialog.setDialogOnclick_One(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (toggle_two) {
                    v.setBackgroundResource(R.mipmap.user_switch_on);
                    toggle_two = false;
                } else {
                    v.setBackgroundResource(R.mipmap.user_switch_off);
                    toggle_two = true;
                }
                editor.putBoolean("toggle_two", toggle_two);
                editor.commit();
            }
        });
        msg_dialog.setDialogOnclick_One(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (toggle_three) {
                    v.setBackgroundResource(R.mipmap.user_switch_on);
                    toggle_three = false;
                } else {
                    v.setBackgroundResource(R.mipmap.user_switch_off);
                    toggle_three = true;
                }
                editor.putBoolean("toggle_three", toggle_three);
                editor.commit();
            }
        });
        msg_dialog.create().show();
    }
}
